<% menu_id = "top-#{SecureRandom.uuid}" %>
<div class="relative">
  <button class="button button__sm button__transparent-secondary" data-controller="dropdown" data-target="dropdown-exports-<%= menu_id %>-<%= dropdown_id(collection_ids) %>">
    <% if collection_ids.present? %>
      <%= t("actions.export-selection", scope: "decidim.admin") %>
    <% else %>
      <%= t("actions.export", scope: "decidim.admin") %>
    <% end %>
    <%= icon "arrow-down-s-line" %>
    <%= icon "arrow-down-s-line" %>
  </button>

  <ul id="dropdown-exports-<%= menu_id %>-<%= dropdown_id(collection_ids) %>" class="dropdown dropdown__bottom" aria-hidden="true">
    <% %w(CSV JSON).each do |format| %>
      <li class="dropdown__item">
        <%= form_with url: export_initiatives_path(format: format), method: :post, class: "dropdown__button" do |f| %>
          <%= hidden_field_tag "collection_ids", collection_ids&.join(",") %>
          <%= f.submit t("decidim.admin.exports.export_as",
                         name: t("decidim.initiatives.admin.exports.initiatives"),
                         export_format: format.upcase) %>
        <% end %>
      </li>
    <% end %>
  </ul>
</div>
